package com.example.springboot.swagger2.configuration;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * <p>
 * </p>
 * http://${host}:${port}/swagger-ui.html
 * http://${host}:${port}/doc.html
 * @author Zero
 * @since 2019-06-18
 */
@EnableSwagger2
@Configuration
public class SwaggerConfiguration {

    @Value("${swagger.enable}")
    private boolean enable;

    @Value("${swagger.basePackage}")
    private String basePackage;

    @Bean
    public Docket api() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(enable)
                .select()
                .apis(RequestHandlerSelectors.basePackage(basePackage))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("API文档")
                .description("API详细说明文档")
                .termsOfServiceUrl("http://www.example.com")
                .contact(new Contact("Mr.Zero","http://www.example.com", "zero@example.com"))
                .version("0.0.1")
                .build();
    }

}
